<template>
  <div class="app-container calendar-list-container" style="margin: 10px">
    <el-form :inline="true" :model="param" @keyup.enter.native="getList"  class="company-wrapper_search" @submit.native.prevent>
      <el-form-item label="共享方案组编号">
        <el-input v-model="pageData.groupNo" placeholder="请输入共享方案组编号"></el-input>
      </el-form-item>
      <el-form-item label="共享方案组名称">
        <el-input v-model="pageData.name" placeholder="请输入共享方案组名称" ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getList(1)" type="primary">查询</el-button>
        <el-button @click="onReset">重置</el-button>
       
      </el-form-item>
  
     
    </el-form>
       <el-button @click="addItem" type="primary"  v-if="this.$can('SHAGRO_ADD')" class="mtb15">新增共享方案组</el-button>
    <nb-table
      :tableHeaders="tableHeaders"
      :tableData="tableData"
      height="auto"
      :align="'center'"
      :clickData="clickData"
      operatorFixed="left"
      operatorText
      @clickRight="clickRight"
      :headerMap="queryMap"
      @selectRow="selectRow"
    ></nb-table>
    <el-pagination
      align="right"
      style="padding-top: 20px;margin-bottom:100px;"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageData.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageData.size"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
  </div>
</template>
 <script>
import NbTable from '@/components/nb-table.vue'
const DEFAULT_DATA = {
  queryParams: '',
  shareSchemeType: ''
}
export default {
  components: {
    NbTable
  },
  data () {
    return {
      param: Object.assign({}, DEFAULT_DATA),
      pageData: {
        groupNo: '',
        name: '',
        size: 10,
        page: 1
      },
      totalPage: 0,
      clickData: [],
      schemeTypelist: {
        shareSchemeType_provideclasses: '服务分类主档',
        shareSchemeType_dictionary: '数据字典',
        shareSchemeType_store: '门店主档',
        shareSchemeType_vendor: '供应商主档'
      },
      queryMap: [
        {
          headerKey: 'isEffect',
          headerName: '是否有效',
          fun (row) {
            if (row.isEffect) {
              return '有效'
            } else if (!row.isEffect) {
              return '无效'
            } else {
              return '-'
            }
          }
        },
        {
          headerKey: 'isDelete',
          headerName: '是否删除',
          fun (row) {
            if (row.isDelete) {
              return '是'
            } else if (!row.isDelete) {
              return '否'
            } else {
              return '-'
            }
          }
        }
      ],
      tableHeaders: [
        {
          headerKey: 'groupNo',
          headerName: '共享方案组编号'
        },
        {
          headerKey: 'name',
          headerName: '共享方案组名称'
        },
        {
          headerKey: 'shareSchemeName',
          headerName: '共享方案名称'
        },
        {
          headerKey: 'remark',
          headerName: '备注'
        }
        // {
        //   headerKey: 'isEffect',
        //   headerName: '是否有效'
        // },
        // {
        //   headerKey: 'isDelete',
        //   headerName: '是否删除'
        // }
      ],
      tableData: [],
      multipleSelection: []
    }
  },
  mounted () {
    this.clickData = this.$showBtn([
      {btnName: 'SHAGRO_EDIT', name: '编辑', type: 'edit'},
      {btnName: 'SHAGRO_DEL', name: '删除', type: 'delete'}
    ])
    this.getList()
    // document.onkeydown = (e) => {
    //   var key = window.event.keyCode
    //   if (key == 13) {
    //     this.getList(1)
    //   }
    // }
  },
  methods: {
    onReset () {
      this.pageData.groupNo = ''
      this.pageData.name = ''
      this.getList(1)
    },
    clickRight (data) {
      if (data.type === 'edit') {
        this.editItem(data.row.code)
      } else if (data.type === 'delete') {
        this.deleteItem(data.row.code)
      }
    },
    getList (page) {
      this.pageData.groupNo = this.pageData.groupNo.trim()
      this.pageData.name = this.pageData.name.trim()
      if (page) {
        this.pageData.page = 1
      }
      this.$http
        .post(
          `/${this.$const.PREFIX.AUTHORITY}/shareSchemeGroup/findAllSSGroupByConditons`,
          this.pageData
        )
        .then(res => {
          if (res.result) {
            this.tableData = res.data.records
            this.totalPage = res.data.total
          }
        })
        .catch(err => {
          this.$message.error(err)
        })
    },
    // 第一个参数是选中的记录组成的数组，第二个参数是当前选择行的数据，是一个对象
    selectRow (selection, row) {
      this.multipleSelection = selection
    },
    addItem () {
      // this.$router.push('/systemSettings/sharePlan/sharePlanAddScheme')
      this.changeRoute()
    },
    changeRoute (pa) {
      console.log('pa: ', pa)
      // this.$router.push({
      //   name: 'sharePlanAddScheme',
      //   params: {
      //     id: pa || 'new'
      //   }
      // })
      this.$router.push({
        name: 'sharePlanAddScheme',
        params: {
          id: pa || 'new'
        }
      })
    },
    editItem (code) {
      // this.$router.push({path: '/systemSettings/sharePlan/sharePlanAddScheme', query: {code: code}})
      code && this.changeRoute(code)
    },
    deleteItem (code) {
      this.$confirm('确认删除该条数据？', '删除确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.post(`/${this.$const.PREFIX.AUTHORITY}/shareSchemeGroup/dels`, {codes: [code]}).then(res => {
          if (res.result) {
            this.pageData.page = 1
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.getList()
          } else {
            this.$message.error({
              message: res.msg,
              duration: 5000
            })
          }
        })
      })
    },
    sizeChangeHandle (val) {
      this.pageData.size = val
      this.getList()
    },
    currentChangeHandle (val) {
      this.pageData.page = val
      this.getList()
    },
    delQueryModel () {}
  }
}
</script>
